package com.mk.controller.user;

import com.mk.entity.DogCard;
import com.mk.result.Result;
import com.mk.service.IDogCardService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;

@RestController
@RequestMapping("/user/dogCard")
@RequiredArgsConstructor
public class DogCardController {

    private final IDogCardService dogCardService;

    /**
     * 犬牌维修
     * @param dogCard
     * @return
     */
    @CrossOrigin
    @PostMapping("/repair")
    public Result repairDogCard(@RequestBody DogCard dogCard) {
        dogCard.setStatus(DogCard.REPAIR);
        dogCard.setCreateTime(LocalDateTime.now());
        dogCard.setUpdateTime(LocalDateTime.now());
        dogCardService.save(dogCard);
        return Result.success();
    }


    /**
     * 犬牌挂失
     * @param dogCard
     * @return
     */
    @CrossOrigin
    @PostMapping("/loss")
    public Result lossReportDogCard(@RequestBody DogCard dogCard) {
        dogCard.setStatus(DogCard.LOSS_REPORT);
        dogCard.setCreateTime(LocalDateTime.now());
        dogCard.setUpdateTime(LocalDateTime.now());
        dogCardService.save(dogCard);
        return Result.success();
    }

    /**
     * 犬牌补办
     * @param dogCard
     * @return
     */
    @CrossOrigin
    @PostMapping("/makeUp")
    public Result makeUpDogCard(@RequestBody DogCard dogCard) {
        dogCard.setStatus(DogCard.MAKE_UP);
        dogCard.setCreateTime(LocalDateTime.now());
        dogCard.setUpdateTime(LocalDateTime.now());
        dogCardService.save(dogCard);
        return Result.success();
    }
}
